package com.crm.service.impl.reminditem;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.common.util.DateUtil;
import com.crm.dao.mapper.customMapper.reminditemCustomMapper.RemindItemCustomMapper;
import com.crm.dao.mapper.reminditem.SysRemindItemMapper;
import com.crm.model.entity.reminditem.SysRemindItem;
import com.crm.model.entity.reminditem.SysRemindItemExample;
import com.crm.model.vo.reminditem.RelatedRemindVO;
import com.crm.service.reminditem.SysRemindItemDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 提醒事项
 * @Author lixq-f
 * @Date 2021/4/20
 * @Version V1.0
 **/
@Service
public class SysRemindItemDbServiceImpl implements SysRemindItemDbService {

    @Autowired
    private SysRemindItemMapper itemMapper;
    @Autowired
    private RemindItemCustomMapper customMapper;

    @Override
    public Boolean insert(SysRemindItem item) {
        return itemMapper.insert(item) > 0;
    }

    @Override
    public Boolean update(SysRemindItem item) {
        return itemMapper.updateByPrimaryKeySelective(item) > 0;
    }

    @Override
    public List<SysRemindItem> selectListByCreatePeopleId(String createPelpleId) {
        SysRemindItemExample example = new SysRemindItemExample();
        SysRemindItemExample.Criteria criteria = example.createCriteria();
        criteria.andCreatePeopleIdEqualTo(createPelpleId);
        criteria.andSetTmGreaterThan(DateUtil.getTodayTime());
        criteria.andDeleteStatusEqualTo((short)StatusCodeEnum.NORMAL_CODE.getState());
        example.setOrderByClause("set_tm asc");
        return itemMapper.selectByExample(example);
    }


    @Override
    public SysRemindItem selectRemindItemById(String id) {
        return itemMapper.selectByPrimaryKey(id);
    }


    @Override
    public Boolean deleteById(String id, short deleteStatus) {
        return customMapper.deleteById(id, deleteStatus);
    }

    @Override
    public Boolean batchDeleteByIds(List<String> ids, short deleteStatus) {
        return customMapper.batchDeleteByIds(ids, deleteStatus);
    }

    /***
     * @Description:获取相关提醒列表
     * @param accountId 账号id
     * @param selectDate 查询日期
     * @param selectDate 查询日期
     * @Author: luojie
     * @Date: 2021/4/27 8:41
     */
    @Override
    public List<RelatedRemindVO> selectRelatedRemindList(String accountId, Date selectDate,String orderStr) {
        List<RelatedRemindVO> relatedRemindVOS = customMapper.selectRelatedRemindList(accountId, selectDate,orderStr);
        return relatedRemindVOS;
    }


}
